namespace com.qt.lib.domain.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddOrderItemClass : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.OrderItem",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        OrderId = c.Long(nullable: false),
                        ProductInfoId = c.Int(nullable: false),
                        Quantity = c.Int(nullable: false),
                        PriceUnit = c.Decimal(nullable: false, precision: 18, scale: 2),
                        SalePrice = c.Decimal(nullable: false, precision: 18, scale: 2),
                        TotalPrice = c.Decimal(nullable: false, precision: 18, scale: 2),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ProductInfo", t => t.ProductInfoId, cascadeDelete: true)
                .ForeignKey("dbo.Order", t => t.OrderId, cascadeDelete: true)
                .Index(t => t.ProductInfoId)
                .Index(t => t.OrderId);
            
            AlterColumn("dbo.ProductInfo", "PriceIn", c => c.Decimal(nullable: false, precision: 18, scale: 2));
            AlterColumn("dbo.ProductInfo", "PriceOutA", c => c.Decimal(nullable: false, precision: 18, scale: 2));
            AlterColumn("dbo.ProductInfo", "PriceOutB", c => c.Decimal(nullable: false, precision: 18, scale: 2));
            AlterColumn("dbo.ProductInfo", "PriceOutC", c => c.Decimal(nullable: false, precision: 18, scale: 2));
            AlterColumn("dbo.ProductInfo", "PriceOutD", c => c.Decimal(nullable: false, precision: 18, scale: 2));
        }
        
        public override void Down()
        {
            DropIndex("dbo.OrderItem", new[] { "OrderId" });
            DropIndex("dbo.OrderItem", new[] { "ProductInfoId" });
            DropForeignKey("dbo.OrderItem", "OrderId", "dbo.Order");
            DropForeignKey("dbo.OrderItem", "ProductInfoId", "dbo.ProductInfo");
            AlterColumn("dbo.ProductInfo", "PriceOutD", c => c.Single(nullable: false));
            AlterColumn("dbo.ProductInfo", "PriceOutC", c => c.Single(nullable: false));
            AlterColumn("dbo.ProductInfo", "PriceOutB", c => c.Single(nullable: false));
            AlterColumn("dbo.ProductInfo", "PriceOutA", c => c.Single(nullable: false));
            AlterColumn("dbo.ProductInfo", "PriceIn", c => c.Single(nullable: false));
            DropTable("dbo.OrderItem");
        }
    }
}
